local AdminPlugin = require('vanilla.v.plugin'):new()

local Check = require("library.checkSession")

function AdminPlugin:routerStartup(request, response)

end

--路由结束，已经算出controller和action结果，在这里做权限判断，比如session
function AdminPlugin:routerShutdown(request, response)
    local action_name = request.action_name
    local controller_name = request.controller_name
    local success,result = Check:session('username',action_name,controller_name)
    --说明没有权限
    if not success then
        ngx.redirect("/admin/login")
    end
end

function AdminPlugin:dispatchLoopStartup(request, response)
--    ngx.say('dispatchLoopStartup')
--    ngx.say('<hr />')
end

function AdminPlugin:preDispatch(request, response)
--    ngx.say('preDispatch')
--    ngx.say('<hr />')
end

function AdminPlugin:postDispatch(request, response)
--    ngx.say('postDispatch')
--    ngx.say('<hr />')
end

function AdminPlugin:dispatchLoopShutdown(request, response)
--    ngx.say('dispatchLoopShutdown')
--    ngx.say('<hr />')
end

return AdminPlugin
